﻿<%@ WebHandler Language="C#" Class="lists" %>
using Models;
using System;
using System.Web;
using Newtonsoft.Json;
using System.Linq;
using Newtonsoft.Json.Linq;
using System.Collections;


public class lists : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";

       // string query = HttpContext.Current.Request.Params["page"];

        string openid = context.Request.Headers["X-ACCESS-USER"];//Header中的token
        string id = "1";

        if (string.IsNullOrEmpty(id))
        {
            HttpContext.Current.Response.Write("parameter error");
            return;
        }

        var code = 1;
        var msg = "获取成功";
        var time = DateTime.Now;


        using (Entities bll = new Entities())
        {
            int _id = int.Parse(id);

            var myclass = bll.S_Classs.Where(x=>x.SCpareID==1).ToList();//全部.ToList();
            ArrayList listclass = new ArrayList();

            foreach (var mcx in myclass)
            {
                var Bpl = bll.S_Goods.Where(xxx=>xxx.childClassId==mcx.SCID &&xxx.GState !=2).OrderBy(x=>x.GSort).ToList();//全部.ToList();

                ArrayList listjson = new ArrayList();
                foreach (var x in Bpl)
                {
                    var imgs = methods.GetImgs(x.GImg);

                    var singTime = "";
                    var iconPath = "/img/ico/" + x.GSort + ".png";
                   // var ispoint = bll.P_T_Sign.FirstOrDefault(s=>s.TaskID==x.GID&&s.UserId==openid);

                     var ispoint = bll.P_T_Sign.FirstOrDefault(s=>s.TaskID==x.GID&&s.UserId==openid &&s.State ==1);

                    if (ispoint != null)
                    {
                        iconPath = "/img/icoa/" + x.GSort + ".png";
                        singTime = ispoint.addtime.ToString();

                    }
                            if (x.childClassId == 30)
                    { 
                       iconPath = "/img/icoa/q.png";
                    }

                    listjson.Add(new
                    {
                        id=x.GID,
                        name=x.GName,
                        latitude=x.Glatitude,
                        longitude=x.Glongitude,
                        iconPath,
                        width=35,
                        height=35,
                        img=imgs,
                        description=x.G_Introduce,
                        x.GSort,
                        singTime

                    });

                };


                listclass.Add( new
                {
                    timg = methods.getFirstImg(mcx.SCSIMG),
                    name = mcx.SCNmae,
                    scale = 10,  //比例尺10-16
                    data = listjson
                });
            }


            var shortName = "广科";

            var name ="ceshi ";
            var   image="/img/ico/jd.png";
            var latitude=22.972816;
            var longitude = 113.756003;

            var description = "<p>创建于2003年，</p>";

            var introduce = new { shortName, name, latitude, longitude,image, description };

            context.Response.Write(JsonConvert.SerializeObject(new { code, msg, time, map=listclass,introduce  }));

        }

        HttpContext.Current.Response.End();
        //context.Response.Write("Hello World");


    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }




}